package com.zzj.portalwebsite.Controller;

import com.alibaba.fastjson.JSON;
import com.zzj.portalwebsite.factory.Factory;
import com.zzj.portalwebsite.utlis.CommonResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/message/delete")
public class DeleteMessageController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String idStr = request.getParameter("id");
        int id = Integer.parseInt(idStr);

        try {
            boolean result = Factory.getFeedBackServiceInstance().deleteFeedBack(id);
            if (result) {
                response.getWriter().write(JSON.toJSONString(CommonResult.success("删除成功")));
            } else {
                response.getWriter().write(JSON.toJSONString(CommonResult.failed("删除失败")));
            }
        } catch (Exception e) {
            e.printStackTrace();
            response.getWriter().write(JSON.toJSONString(CommonResult.failed("服务器异常")));
        }
    }
}